package QuanLyNhanSu;

import java.awt.Color;
import java.awt.Font;
import java.awt.Rectangle;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import java.awt.Point;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Vector;

public class frmMain extends JFrame{
	
	SetControl set = new SetControl();
	
	JButton jbt_Tim = new JButton("Tìm kiếm"),			
			jbt_Them = new JButton("Thêm"),
			jbt_Xoa = new JButton("Xóa"),
			jbt_Sua = new JButton("Sửa"),
			jbt_CapNhat = new JButton("Cập nhật lại"),
			jbt_Thoat = new JButton("Thoát");
	
	JLabel 	jlb_TieuDe = new JLabel("QUẢN LÝ NHÂN SỰ"),
			jlb_Tim = new JLabel("Tìm kiếm");
	
	JTextField jtf_Tim = new JTextField();
	
	JTable jtb_NhanSu;
	
	String[] header ={"Mã nhân viên", "Họ và tên", "Giới tính", "Điện thoại", "Email", 
			"Năm sinh", "Hệ số lương", "Hệ sống phụ cấp", "Chức vụ","Phòng ban", "Lương"};
	
	DefaultTableModel dtm;
	
	public void SetLayout(){
		jlb_TieuDe.setForeground(new Color(0, 128, 128));
		jlb_TieuDe.setFont(new Font("Tahoma", Font.BOLD, 35));
		jlb_TieuDe.setBounds(new Rectangle(430,10,500,40));
		
		dtm=new DefaultTableModel(header, 0);		
	    jtb_NhanSu = new JTable(dtm);
	    
	    set.setFont(jtb_NhanSu);
		set.setFont(jlb_Tim);set.setFont(jtf_Tim);set.setFont(jbt_Tim);
		set.setFont(jbt_Them);set.setFont(jbt_Xoa);set.setFont(jbt_Sua);
		set.setFont(jbt_CapNhat);set.setFont(jbt_Thoat);
		
		jlb_Tim.setBounds(new Rectangle(10,70,100,25));
		jtf_Tim.setBounds(new Rectangle(100,70,300,25));
		jbt_Tim.setBounds(new Rectangle(410,70,100,25));
		jbt_Them.setBounds(new Rectangle(520,70,100,25));
		jbt_Xoa.setBounds(new Rectangle(630,70,100,25));
		jbt_Sua.setBounds(new Rectangle(740,70,100,25));
		jbt_CapNhat.setBounds(new Rectangle(850,70,100,25));
		jbt_Thoat.setBounds(new Rectangle(1080,70,100,25));
		
	    JScrollPane scrollPane = new JScrollPane(jtb_NhanSu);
	    
	    jtb_NhanSu.setRowHeight(25);
	    jtb_NhanSu.getTableHeader().setForeground(new Color(0, 128, 128));
	    jtb_NhanSu.getTableHeader().setFont(new Font("Tahoma", Font.BOLD, 16));
	    scrollPane.setBounds(new Rectangle(10,100,1170,500));
	    
	    add(jlb_TieuDe);
		add(jlb_Tim);add(jtf_Tim);add(jbt_Tim);
		add(jbt_Them);add(jbt_Xoa);add(jbt_Sua);
		add(jbt_CapNhat);add(jbt_Thoat);
		add(scrollPane);
		
	    try {
			LoadDBData();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
	
	public void LoadDBData() throws Exception{
        
		Conn c = new Conn("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\Hoc Tap\\Hoc Ki VII\\Chuyen De Java\\OnTap_Code\\OnTap\\src\\QuanLyNhanSu\\QLNhanSu.mdb;}", "", "");
		try {
			String sql = "SELECT * FROM NhanSu";
			ResultSet rs = c.executeQ(sql);
			//dtm.
			while (rs.next()) {
			      // Get data 
				NhanSu nsu = new NhanSu();
				nsu.MaNV = rs.getString(1);
				nsu.HoTen = rs.getString(2);
				nsu.GioiTinh = rs.getString(3);
				nsu.SoDT = rs.getString(4);
				nsu.Email = rs.getString(5);
				nsu.NamSinh = rs.getInt(6);
				nsu.HeSoLuong = rs.getFloat(7);
				nsu.HeSoPhuCap = rs.getFloat(8);
				nsu.ChucVu = rs.getString(9);
				nsu.PhongBan = rs.getString(10);
				NhanSu ns = new NhanSu(nsu);
				Object []row={ns.MaNV, ns.HoTen, ns.GioiTinh, ns.SoDT, ns.Email, 
						ns.NamSinh, ns.HeSoLuong, ns.HeSoPhuCap, ns.ChucVu, ns.PhongBan, ns.Luong};
	            dtm.addRow(row);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
    }
	
	public frmMain(){
		setSize(1205, 645);
		setVisible(true);
		setTitle("Quản lý nhân sự");
		setLayout(null);
		SetLayout();
		setMaximizedBounds(new Rectangle(0, 0, 1205, 645));
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new frmMain();
	}

}
